<?php

namespace app\admin\controller\system;

use app\admin\controller\BaseController;
use think\Db;

/**
 * 用户组管理
 * Class GroupController
 * @package app\admin\controller\auth
 */
class OperateController extends BaseController
{

    /**
     * 主页面
     * @return mixed
     */
    public function index()
    {
        return view();
    }

    public function login()
    {
        return view();
    }

    public function lists()
    {
        $map = array();
        $data = array();
        $post = $this->request->param();
        unset($post['page']);
        unset($post['limit']);

        $data['count'] = Db::view('operate', 'id,uid,c_time,info,content')
            ->view('admin', 'nickname', 'operate.uid=admin.id', 'LEFT')
            ->where($post)
            ->count();
        // echo Db::name('supplier')->where($map)->fetchSql(true)->select();
        $data['data'] =  Db::view('operate', 'id,uid,c_time,info,content')
            ->view('admin', 'nickname', 'operate.uid=admin.id', 'LEFT')
            ->where($post)
            // ->fetchSql(true)
            ->order('operate.id desc')->page(input("page"), input('limit'))->select();

        if ($data['count'] > 0 && $data['data']) {
            $data['msg'] = '获取成功';
        } else {
            $data['msg'] = '获取数据为空';
        }
        $data['code'] = 0;
        return json($data);
    }

    public function loginlists()
    {
        $map = array();
        $data = array();
        $post = $this->request->param();
        unset($post['page']);
        unset($post['limit']);

        $data['count'] = Db::name('login')
            ->where($post)
            ->count();
        // echo Db::name('supplier')->where($map)->fetchSql(true)->select();
        $data['data'] =   Db::name('login')

            ->where($post)
            // ->fetchSql(true)
            ->order('id desc')->page(input("page"), input('limit'))->select();

        if ($data['count'] > 0 && $data['data']) {
            $data['msg'] = '获取成功';
        } else {
            $data['msg'] = '获取数据为空';
        }
        $data['code'] = 0;
        return json($data);
    }



    public function add()
    {
        if ($this->request->isPost()) {
            $post = $this->request->param();
            if (!isset($post['name']) || empty($post['name'])) {
                $this->error(' 分类名称不能为空');
            }

            if (!isset($post['price']) || empty($post['price'])) {
                $this->error('点数不能为空');
            }
            if (!isset($post['time_len']) || empty($post['time_len'])) {
                $this->error('时间不能为空');
            }
            if ($post['time_len']<1) {
                $this->error('时间必须为数字');
            }
            if ($post['price']<1) {
                $this->error('点数必须为数字');
            }
            $post['model_id'] = 3;
            $post['status'] = 1;
            if (Db::name('category')->insert($post) !== false) {
                $this->success('操作成功');
            }
            $this->error('添加失败');

        } else {

            return view();
        }
    }




    public function delete()
    {
        if ($this->request->isPost()) {
            $post = $this->request->param();

            if (!isset($post['id'])) {
                $this->error('请求参数错误');
            }

            if (Db::name('category')->delete($post) !== false) {
                $this->success('操作成功!');
            }
            $this->error('更新失败');
        }
    }


}